package leetcode.Y2024M6.review;

import org.junit.Test;

public class S121 {
    public int maxProfit(int[] prices) {
        int minVal=Integer.MAX_VALUE;
        int res=0;
        for (int i = 0; i < prices.length; i++) {
            minVal=Math.min(minVal,prices[i]);
            res=Math.max(res,prices[i]-minVal);
        }
        return res;

    }

    @Test
    public void test(){
        int[] prices={7,1,5,3,6,4};
        int i = maxProfit(prices);
        System.out.println(i);

    }
    @Test
    public void test1(){
        int[] prices={7,6,4,3,1};
        int i = maxProfit(prices);
        System.out.println(i);

    }
}
